package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRegionMapper;
import com.qf.pojo.DtsRegion;
import com.qf.service.DtsRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author wanghaotian
 * time:2022/12/21,0021 14:39
 * description:
 */

@Service
public class DtsRegionServiceImpl implements DtsRegionService {

    @Autowired
    private DtsRegionMapper regionMapper;

    @Override
    public IPage<DtsRegion> findPage(Integer page, Integer limit, String name, Integer code, String sort, String order) {
        IPage<DtsRegion> iPage = new Page<>(page,limit);
        QueryWrapper<DtsRegion> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            wrapper.like("name", name);
        }
        if (code != null) {
            wrapper.eq("code", code);
        }
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            if (order.equalsIgnoreCase("desc")) {
                wrapper.orderByDesc(sort);
            }else {
                wrapper.orderByAsc(sort);
            }
        }
        iPage = regionMapper.selectPage(iPage, wrapper);
        return iPage;
    }
}
